package com.easyjava.qingke.memo.command;

import java.util.HashMap;
import java.util.Map;

import com.easyjava.qingke.memo.command.impl.AddCommand;
import com.easyjava.qingke.memo.command.impl.ChangeCommand;
import com.easyjava.qingke.memo.command.impl.DeleteCommand;
import com.easyjava.qingke.memo.command.impl.ExitCommand;
import com.easyjava.qingke.memo.command.impl.HelpCommand;
import com.easyjava.qingke.memo.command.impl.ListCommand;
import com.easyjava.qingke.memo.command.impl.SelectCommand;

public class SystemCommandFactory extends CommandFactory {
     
	private static Map<CommandCode,Class<?extends Command>> systemCommandMap=new HashMap<CommandCode,Class<?extends Command>>();
	
	static{
		systemCommandMap.put(CommandCode.ADD, AddCommand.class);
		systemCommandMap.put(CommandCode.CHANGE, ChangeCommand.class);
		systemCommandMap.put(CommandCode.EXIT, ExitCommand.class);
		systemCommandMap.put(CommandCode.HELP, HelpCommand.class);
		systemCommandMap.put(CommandCode.DELETE,DeleteCommand.class);
		systemCommandMap.put(CommandCode.SELECT, SelectCommand.class);
		systemCommandMap.put(CommandCode.LIST, ListCommand.class);
	}
	
	
	
	@Override
	public Command buildCommand(CommandCode cmdCode) {
		Class<?extends Command>cmdClass =systemCommandMap.get(cmdCode);
		
		if(cmdClass!=null){	
			try {
				return cmdClass.newInstance();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		return null;
	}

}
